var mysql = require('mysql')
var log = require("./../../util/loginfo").getInstand;
var mysql_config=require("../../util/mysql_config");
const { now } = require('lodash');

var pool = mysql.createPool({
	connectionLimit:10000,
	host:mysql_config.host,
	user:mysql_config.user,
	password:mysql_config.password,
	port:mysql_config.port,
	database:'gameaccount'
})

//获取充值记录
exports.getPayRecord = function getPayRecord(callback){
	var sql = "SELECT * FROM mark as A \
	left join newuseraccounts as B on A.userId = B.Id \
	WHERE A.useCoin > 0 and A.ispaybackfee = 0 and B.`level` > 0 and DATE(A.balanceTime) <= DATE_SUB(CURDATE(), INTERVAL 1 DAY) limit 1";
	pool.getConnection(function(err,connection){
		connection.query({sql:sql},function(err,rows){
			connection.release();
			if (err)
			{
				log.err(mark, err);
				
				callback(0);
			}else{
				if (rows[0]){
					callback(1,rows);
				}else{
					callback(0);
				}
			}})
	});
}

exports.setBackFeeStatus = function setBackFeeStatus(id, value, callback){
	var sql = "UPDATE mark SET ispaybackfee = ? WHERE id = ?";
	var values = [];
	values.push(value);
	values.push(id);

	log.info("setBackFeeStatus begin");
	pool.getConnection(function(err,connection){
		connection.query({sql:sql,values:values},function(err,rows){
			if (err)
			{
				log.err("setBackFeeStatus");
				log.err(err);
				callback(0);
			}else{
				callback(1);
			}})
			connection.release();
	});
}

